<?php

	class CountAction extends Action{
		//统计全年级的相关信息
		public function countGrade(){
			$grade=$_POST["getgrade"];
			if (empty($grade)) {//如果年级条件为空的话直接显示页面
				echo $this->fetch();
 				exit();
			}
			$where["grade"]=$grade;
			$count=D("Count");
			$getCount=$count->getCountInfo($where);
			$getCount["grade"]=$grade;
			$this->assign("countInfo",$getCount);
			echo $this->fetch("Page:countgrade");
			
			
		}
		
		public function countMajor(){
			$major=$_POST["getmajor"];
			$grade=$_POST["getgrade"];
			if (empty($major)) {//如果年级条件为空的话直接显示页面
				echo $this->fetch();
 				exit();
			}
			$where["grade"]=$grade;
			$where["major"]=$major;
			$count=D("Count");
			$getCount=$count->getCountInfo($where);
			$this->assign("countInfo",$getCount);
			echo $this->fetch("Page:countmajor");
		}
		//统计班级的相关信息
		public function countClass(){
			$grade=$_POST["getgrade"];
			$major=$_POST["getmajor"];
			$class=$_POST["getclass"];
			if (empty($grade)||empty($major)||empty($class)) {//如果必要参数有一个为空的话就直接输出页面
				echo $this->fetch();
				exit();
			}
			//将字段查询的条件设为整数值查询
			$where["grade"]=(int)$grade;
			$where["major"]=(int)$major;
			$where["class"]=(int)$class;
			$count=D("Count");
			$getCount=$count->getCountInfo($where);
			$this->assign("countInfo",$getCount);
			echo $this->fetch("Page:countclass");
		}
		//统计班级的补考信息
		public function countBk(){
			$grade=$_POST["getgrade"];
			$major=$_POST["getmajor"];
			$class=$_POST["getclass"];
 			$year=(int)$_POST["getyear"];
 			$mode=$_POST["mode"];
			if (empty($grade)||empty($major)||empty($class)||empty($year)||empty($mode)) {//若必要参数为空的话，则直接显示页面
				echo $this->fetch();
				exit();
			}
			$count=D("Count");
			$return=$count->getClassBkinfo($grade,$major,$class,$year,$mode);//获得班级的补考信息系，原型定义在CountModel中
			$this->assign("classbkinfo",$return);
			echo $this->fetch("Page:countbk");
		}
		//统计年级，专业或班级奖励的获得情况
		public function countJiangLi(){
			$grade=(int)$_POST["getgrade"];
			$major=(int)$_POST["getmajor"];		
			$class=(int)$_POST["getclass"];
			$year=(int)$_POST["getyear"];
			$type=$_POST["gettype"];
			$range=$_POST["range"];
			$request=$_POST["request"];
			if ($request=="page"||empty($request)) {
				echo $this->fetch();
				exit();
			}
			$count=D("Count");
			$st=M("Baseinfo");
			$base=D("Base");
			switch($range){//针对查询条件的不同，返回不同类型的数据
				case "allgrade":
					$sidList=$st->where("grade=".(int)$grade)->field("sid")->select();//获得全年级学生的学号列表
					$c=count($sidList);
					for($i=0;$i<$c;$i++){
						if ((int)$count->checkSanctioBySID($sidList[$i]["sid"],$type,$year)==1) {//判断当前学生是否获得了type中定义的奖励类型
							$result[$i]["sid"]=$sidList[$i]["sid"];
							$result[$i]["name"]=$base->getSIDinfo($result[$i]["sid"],"name","name");
							$result[$i]["sex"]=$base->getSIDinfo($result[$i]["sid"],"sex","name");
							$result[$i]["grade"]=$base->getSIDinfo($result[$i]["sid"],"grade","name");
							$result[$i]["major"]=$base->getSIDinfo($result[$i]["sid"],"major","name");
							$result[$i]["class"]=$base->getSIDinfo($result[$i]["sid"],"class","name");
						}
					}
					break;
				case "allmajor":
					$where["grade"]=$grade;
					$where["major"]=$major;
					$sidList=$st->where($where)->field("sid")->select();
					$c=count($sidList);
					for($i=0;$i<$c;$i++){
						if ((int)$count->checkSanctioBySID($sidList[$i]["sid"],$type,$year)==1) {
							$result[$i]["sid"]=$sidList[$i]["sid"];
							$result[$i]["name"]=$base->getSIDinfo($result[$i]["sid"],"name","name");
							$result[$i]["sex"]=$base->getSIDinfo($result[$i]["sid"],"sex","name");
							$result[$i]["grade"]=$base->getSIDinfo($result[$i]["sid"],"grade","name");
							$result[$i]["major"]=$base->getSIDinfo($result[$i]["sid"],"major","name");
							$result[$i]["class"]=$base->getSIDinfo($result[$i]["sid"],"class","name");
						}
					}
					break;
				case "allclass":
					$where["grade"]=$grade;
					$where["major"]=$major;
					$where["class"]=$class;
					$sidList=$st->where($where)->field("sid")->select();
					$c=count($sidList);
					for($i=0;$i<$c;$i++){
						if ((int)$count->checkSanctioBySID($sidList[$i]["sid"],$type,$year)==1) {
							$result[$i]["sid"]=$sidList[$i]["sid"];
							$result[$i]["name"]=$base->getSIDinfo($result[$i]["sid"],"name","name");
							$result[$i]["sex"]=$base->getSIDinfo($result[$i]["sid"],"sex","name");
							$result[$i]["grade"]=$base->getSIDinfo($result[$i]["sid"],"grade","name");
							$result[$i]["major"]=$base->getSIDinfo($result[$i]["sid"],"major","name");
							$result[$i]["class"]=$base->getSIDinfo($result[$i]["sid"],"class","name");
						}
					}
					break;
				default:
					echo "error";
			}
			$this->assign("num",count($result));
			$this->assign("sanction",$result);
			echo $this->fetch("Page:countjiangli");		
		}
		public function countCF(){
			$type=$_POST["type"];
			$year=$_POST["getyear"];
			switch($type){
				case "class":
					$where["grade"]=$_POST["getgrade"];
					$where["major"]=$_POST["getmajor"];
					$where["class"]=$_POST["getclass"];
					break;
				case "major":
					$where["grade"]=$_POST["getgrade"];
					$where["major"]=$_POST["getmajor"];
					break;
				case "grade":
					$where["grade"]=$_POST["getgrade"];
					break;
				default:
					echo $this->fetch();
					exit;
			}
			$st=M("Baseinfo");
			$sidList=$st->where($where)->field("sid")->select();
			$count=count($sidList);
			$getSt=D("Base");
			$cf=M("Sanctioninfo");
			for($i=0;$i<$count;$i++){
				$w["sid"]=$sidList[$i]["sid"];
				$w["year"]=$year;
				$cfinfo=$cf->where($w)->getField("cf");
				if(!empty($cfinfo)){
					$stInfo[$i]["sid"]=$sidList[$i]["sid"];
					$stInfo[$i]["name"]=$getSt->getSIDinfo($sidList[$i]["sid"],"name","name");
					$stInfo[$i]["grade"]=$getSt->getSIDinfo($sidList[$i]["sid"],"grade","name");
					$stInfo[$i]["major"]=$getSt->getSIDinfo($sidList[$i]["sid"],"major","name");
					$stInfo[$i]["class"]=$getSt->getSIDinfo($sidList[$i]["sid"],"class","name");
					$stInfo[$i]["cf"]=$cfinfo;
				}
			}
			$this->assign("num",count($stInfo));
			$this->assign("info",$stInfo);
			echo $this->fetch("Page:countcf");
		}
		
		public function countParty(){
			$type=$_POST["type"];
			switch($type){
				case "class":
					$where["grade"]=$_POST["getgrade"];
					$where["major"]=$_POST["getmajor"];
					$where["class"]=$_POST["getclass"];
					break;
				case "major":
					$where["grade"]=$_POST["getgrade"];
					$where["major"]=$_POST["getmajor"];
					break;
				case "grade":
					$where["grade"]=$_POST["getgrade"];
					break;
				default:
					echo $this->fetch();
					exit;
			}
			$partyType=$_POST["getparty"];
			$st=M("Baseinfo");
			$sidList=$st->where($where)->field("sid")->select();
			$count=count($sidList);
			$getSt=D("Base");
			$party=D("Count");
			$a=0;
			for($i=0;$i<$count;$i++){
				
				if($party->checkPartyType($sidList[$i]["sid"],$partyType)){
					$a++;
					$result[$i]["sid"]=$sidList[$i]["sid"];
					$result[$i]["name"]=$getSt->getSIDinfo($sidList[$i]["sid"],"name","name");
					$result[$i]["grade"]=$getSt->getSIDinfo($sidList[$i]["sid"],"grade","name");
					$result[$i]["major"]=$getSt->getSIDinfo($sidList[$i]["sid"],"major","name");
					$result[$i]["class"]=$getSt->getSIDinfo($sidList[$i]["sid"],"class","name");
				}else{
					$a++;
				}
			}
			$this->assign("num",count($result));
			$this->assign("result",$result);
			echo $this->fetch("Page:countparty");
		}
	}

?>